<template>
  <div v-loading="loading" id="editCompany">
    <div :class="{ informationWidth: isCheck || isEdit || $route.query.type == 1 }" class="information_left">
      <el-form :model="Information" :rules="rules" ref="Information" label-width="80px" class="demo-ruleForm">
        <el-col>
          <div class="grid-content bg-purple-dark span_blo" style="width: 100%">
            <span class="_span">企业基本信息</span>
          </div>
        </el-col>
        <div v-if="accountName" class="theForm">
          <el-form-item label="企业名称:" prop="subName" class="spaci">
            <el-input v-model.trim="Information.subName" clearable></el-input>
          </el-form-item>
          <span class="business_span" @click="GetInformation">获取工商信息</span>
          <el-form-item label="企业简称:" prop="abbreviationName" class="spaci1">
            <el-input v-model.trim="Information.abbreviationName" clearable></el-input>
          </el-form-item>
          <el-form-item label="企业编码:" prop="subNumber" class="spaci1">
            <el-input v-model="Information.subNumber" clearable></el-input>
          </el-form-item>
        </div>
        <div>
          <ul class="information_left_List" v-if="paragraph" style="margin-top: 1.5%">
            <li :class="{ item: examine, duty: modificationL, first: modificationL }">
              <span>企业名称: </span>
              <p style="letter-spacing: 1px">{{ Information.subName }}</p>
            </li>
            <li :class="{ item: examine, duty: modificationL, first: modificationL }">
              <span>企业简称: </span>
              <p style="letter-spacing: 1px">{{ Information.abbreviationName }}</p>
            </li>
            <li :class="{ item: examine, duty: modificationL, noleft: modificationL }">
              <span>企业编码: </span>
              <p>{{ Information.subNumber }}</p>
            </li>
          </ul>
          <ul v-if="examine" class="information_left_List">
            <li :class="{ item: examine, duty: modificationL, first: modificationL }">
              <span>企业税号: </span>
              <p style="letter-spacing: 1px">{{ Information.taxNumber }}</p>
            </li>
            <li :class="{ item: examine, duty: modificationL, noleft: modificationL }">
              <span>企业类型:</span>
              <p>{{ Information.taxTypeName }}</p>
            </li>
          </ul>
          <div v-if="modificationL" class="territory">
            <el-form-item label="企业税号:" prop="taxNumber" class="taxNumber">
              <el-input v-model="Information.taxNumber" clearable></el-input>
            </el-form-item>
            <el-form-item label="企业类型:" prop="taxType" class="taxType1" placeholder="请选择报税类别" v-if="!paragraph">
              <el-select v-model="Information.taxType" @change="changetaxTypeName">
                <el-option label="一般纳税人" :value="2"></el-option>
                <el-option label="小规模纳税人" :value="1"></el-option>
              </el-select>
            </el-form-item>
            <div v-else class="item">
              <span>企业类型:</span>
              <p>{{ Information.taxTypeName }}</p>
            </div>
          </div>
          <ul class="information_left_List">
            <li :class="{ item: examine, redact: modificationL, first: modificationL, itemlength: modificationL }" style="width: 90%">
              <span class="itemspan" style="float: left">备</span>
              <span style="float: left">注: </span>
              <p v-if="examine" style="float: left; width: 80%">{{ Information.remarks }}</p>
              <el-form-item v-if="modificationL" prop="remarks" class="Remarkstyle">
                <el-input autosize type="textarea" v-model="Information.remarks"></el-input>
              </el-form-item>
            </li>
          </ul>
        </div>
        <el-col>
          <div class="grid-content bg-purple-dark span_blo">
            <ul class="bomNavigation clearfix MyAccount_list" style="margin-top: 12px">
              <li v-for="item in navs" :key="item.name" :class="{ bomNavigationActive: item.isActive }" @click="activeItemNav(item)">{{ item.name }}</li>
            </ul>
          </div>
        </el-col>
        <div v-show="isBusiness">
          <ul class="information_left_List Industry" style="margin-top: 1.5%">
            <li :class="{ item: examine, redact: modificationL, first: modificationL }">
              <span class="itemspan">类</span>
              <span>型:</span>
              <el-input v-show="modificationL" v-model="businessModel.typeName"></el-input>
              <p v-show="examine">{{ businessModel.typeName }}</p>
            </li>
            <li :class="{ item: examine, redact: modificationL }">
              <span>注册资本 :</span>
              <el-input v-show="modificationL" v-model="businessModel.registerCapital"></el-input>
              <p v-show="examine">{{ businessModel.registerCapital }}</p>
            </li>
            <li :class="{ item: examine, redact: modificationL }">
              <span>成立日期 :</span>
              <el-date-picker v-show="modificationL" v-model="businessModel.buildDate" value-format="yyyy-MM-dd" type="date" placeholder="选择日期"> </el-date-picker>
              <p v-show="examine">{{ businessModel.buildDate }}</p>
            </li>
          </ul>
          <ul class="information_left_List">
            <li :class="{ item: examine, redact: modificationL, first: modificationL, itemlength: modificationL }">
              <span class="itemspan">地</span>
              <span>址:</span>
              <el-input v-show="modificationL" v-model="businessModel.address"></el-input>
              <p v-show="examine">{{ businessModel.address }}</p>
            </li>
          </ul>
          <ul class="information_left_List">
            <li :class="{ item: examine, redact: modificationL, first: modificationL, itemlength: modificationL }" style="width: 90%">
              <span style="float: left">经营范围: </span>
              <el-form-item v-show="modificationL" prop="businessScope" class="ScopeStyle">
                <el-input autosize type="textarea" v-model="businessModel.businessScope" maxlength="1000"></el-input>
              </el-form-item>
              <p v-show="examine" style="float: left; width: 80%">{{ businessModel.businessScope }}</p>
            </li>
          </ul>
          <ul class="information_left_List" style="height: 150px">
            <li :class="{ item: examine, redact: modificationL, first: modificationL }">
              <span class="itemspan">法</span>
              <span>人:</span>
              <el-input v-show="modificationL" v-model="businessModel.legalPerson"></el-input>
              <p v-show="examine">{{ businessModel.legalPerson }}</p>
            </li>
            <li :class="{ item: examine, redact: modificationL }">
              <span class="IDNumberSpan">身份证号 :</span>
              <el-form-item v-show="modificationL" prop="codeNumber" class="IDNumberStyle">
                <el-input v-model="Information.codeNumber" @blur="businessModel.codeNumber = Information.codeNumber"></el-input>
              </el-form-item>
              <p v-show="examine">{{ Information.codeNumber }}</p>
            </li>
          </ul>
        </div>
        <div v-show="!isBusiness" class="IndustryDocument">
          <div class="IndustryDocument_title">
            <span class="title_span"></span>
            <span>税务信息</span>
          </div>
          <ul class="information_left_List">
            <li class="item" style="margin-left: 1.5%; margin-top: 0">
              <span class="IDNumberSpan">国税密码:</span>
              <el-form-item v-show="modificationL" prop="dsPwd" class="TaxPasswordStyle">
                <el-input v-model="Information.dsPwd" @blur="taxationModel.dsPwd = Information.dsPwd"></el-input>
              </el-form-item>
              <p v-show="examine">{{ taxationModel.dsPwd }}</p>
            </li>
            <li class="item" :class="{ anchor: examine }" style="margin-top: 0">
              <span class="IDNumberSpan">个税申报密码:</span>
              <el-form-item v-show="modificationL" prop="gsPwd" class="TaxPasswordStyle">
                <el-input v-model="Information.gsPwd" @blur="taxationModel.gsPwd = Information.gsPwd"></el-input>
              </el-form-item>
              <p v-show="examine">{{ taxationModel.gsPwd }}</p>
            </li>
          </ul>
          <div class="IndustryDocument_title">
            <span class="title_span"></span>
            <span>银行信息</span>
          </div>
          <el-table border :data="Banks" style="width: 100%">
            <el-table-column label="开户行" align="center">
              <template slot-scope="scope">
                <el-input v-if="scope.row.rormBood" v-model="scope.row.bankShareName"></el-input>
                <p style="text-align: center" v-else>{{ scope.row.bankShareName }}</p>
              </template>
            </el-table-column>
            <el-table-column align="center" label="账号">
              <template slot-scope="scope">
                <el-input v-if="scope.row.rormBood" placeholder="请输入银行账号" v-model="scope.row.code"></el-input>
                <p style="text-align: center" v-else>{{ scope.row.code }}</p>
              </template>
            </el-table-column>
            <el-table-column v-show="modificationL" align="center" label="操作">
              <template slot-scope="scope">
                <el-button type="text" size="small" v-show="scope.$index == 0" @click="addIncreased(scope.$index, scope.row)">新增</el-button>
                <el-button type="text" size="small" @click="deleteTable(scope.$index, scope.row)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
          <div class="IndustryDocument_title"><span class="title_span"></span>股东信息</div>
          <el-table border :data="Shareholds" style="width: 100%">
            <el-table-column label="股东姓名" align="center">
              <template slot-scope="scope">
                <el-input v-show="scope.row.rormBood" v-model="scope.row.bankShareName"></el-input>
                <p style="text-align: center" v-show="!scope.row.rormBood">{{ scope.row.bankShareName }}</p>
              </template>
            </el-table-column>
            <el-table-column align="center" label="身份证号">
              <template slot-scope="scope">
                <el-input v-show="scope.row.rormBood" v-model="scope.row.code"></el-input>
                <p style="text-align: center" v-show="!scope.row.rormBood">{{ scope.row.code }}</p>
              </template>
            </el-table-column>
            <el-table-column v-show="modificationL" align="center" label="操作">
              <template slot-scope="scope">
                <el-button type="text" size="small" v-show="scope.$index == 0" @click="addIncreasedx(scope.$index, scope.row)">新增</el-button>
                <el-button type="text" size="small" @click="deleteTablex(scope.$index, scope.row)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </el-form>
    </div>
    <div class="information_right" v-show="!isCheck && !isEdit && $route.query.type != 1">
      <el-form :model="Information1" :rules="rules1" ref="Information1" label-width="100px" class="demo-ruleForm">
        <el-col>
          <div class="grid-content bg-purple-dark span_blo" style="width: 100%">
            <span class="_span">启用账套<el-switch v-model="Information.isEnableAccount"></el-switch></span>
            <span @click="goNotice" class="__span">建账须知</span>
          </div>
        </el-col>
        <el-form-item label="" label-width="0" v-show="Information.isEnableAccount">
          <el-radio-group class="radiogroup" v-model="Information1.accountType">
            <el-radio :label="0">创建账套</el-radio>
            <el-radio :label="1">克隆账套</el-radio>
            <el-radio :label="2">导入账套</el-radio>
          </el-radio-group>
        </el-form-item>
        <!-- <el-form-item label="公司名称:">
                <span style="color:#606266">{{ userInfo.abbreviationName || userInfo.subName }}</span>
            </el-form-item> -->
        <el-form-item label="启用年月:" v-show="Information1.accountType != 2 && Information.isEnableAccount" prop="startYm">
          <el-date-picker type="month" placeholder="选择月" format="yyyy年MM月" value-format="yyyy-MM" v-model="Information1.startYm"></el-date-picker>
        </el-form-item>
        <el-form-item label="会计制度:" v-show="Information1.accountType == 0 && Information.isEnableAccount" prop="accountingSystemId">
          <el-select v-model="Information1.accountingSystemId" filterable>
            <el-option v-for="item in codePreSets" :key="item.id" :label="item.systemName" :value="item.id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="克隆账套:" v-show="Information1.accountType == 1 && Information.isEnableAccount" prop="cloneAccountId" placeholder="请选择克隆账套">
          <el-select v-model="Information1.cloneAccountId" filterable>
            <el-option v-for="item in cloneZtInfos" :key="item.accountId" :label="item.subName" :value="item.accountId"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="所属行业:" v-show="Information1.accountType != 2 && Information.isEnableAccount" prop="industryid" placeholder="请选择所属行业">
          <el-select v-model="Information1.industryid" filterable>
            <el-option v-for="item in customerIndusts" :key="item.id" :label="item.industryName" :value="item.id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item v-show="Information1.accountType == 2 && Information.isEnableAccount">
          <span class="redColorFont" style="position: relative; left: -50px">*如需导入账套请先保存账套基本信息</span>
          <!-- <span class="redColorFont">由升级工具直接升级的xml文件</span>
          <el-button type="primary" style="display: block;margin-top: 5px;" round @click="Oneclickimport">一键式导入</el-button> -->
        </el-form-item>
        <div v-show="!Information.isEnableAccount" style="height: 283px"></div>
        <el-col v-if="jurisdictionControl.sales">
          <div class="grid-content bg-purple-dark span_blo" style="width: 100%">
            <span class="_span">启用进销存<el-switch v-model="Information.isEnableSell"></el-switch></span>
          </div>
        </el-col>
      </el-form>
    </div>
    <div class="information_bottom">
      <el-button type="info" v-show="isButton" round @click="closeCurrentTags" size="medium">取 消</el-button>
      <el-button type="primary" v-show="isButton" :loading="isConfirmLoading" round @click="preserve('Information')" size="medium">保 存</el-button>
      <el-button type="info" v-show="!isButton" round @click="closeCurrentTags" size="medium">返 回</el-button>
      <el-button type="primary" v-show="!isButton && !isCheck && jurisdictionControl.J_EditFirm" round @click="edit" size="medium">编 辑</el-button>
    </div>
    <!-- 财务一键式导入 -->
    <el-dialog title="财务一键式导入" v-if="Visiblenel" :visible.sync="Visiblenel" :close-on-click-modal="false" :before-close="close" class="Visiblenel">
      <iframe style="border: 0" width="100%" height="100%" scrolling="no" :src="iframeSrc"></iframe>
    </el-dialog>
  </div>
</template>
<script>
import * as Vrules from "@/util/validate";
import { GetSubCompanyDataView } from "@/hooks/update";
import { mapState } from "vuex";
import webUrl from "@/config/otherLink";
export default {
  name: "editCompany",
  props: ["isEdit", "isCheck", "jurisdictionControl", "parentId"],
  data() {
    return {
      navs: [
        {
          name: "工商信息",
          isActive: true,
        },
        {
          name: "税务、银行、股东信息",
          isActive: false,
        },
      ],
      businessModel: {
        // accountid:'',//账套id
        typeName: "", //类型名称
        registerCapital: "", // 注册资本
        buildDate: "", // 成立日期
        address: "", // 地址
        businessScope: "", // 经营范围
        legalPerson: "", // 法人
        codeNumber: "", // 身份证号
      },
      Shareholds: [
        // 股东信息
      ],
      Banks: [
        // 银行信息
      ],
      showButton: false,
      taxationModel: {
        dsPwd: "", //国税
        gsPwd: "", //个人
      },
      isBusiness: true, // 工商信息 税务、银行、股东信息  切换
      Information: {
        // 账套信息对象
        parentId: "", // 子公司id
        subName: "", //  企业名称
        abbreviationName: "", //企业简称
        subNumber: "", //企业编码
        taxNumber: "", // 企业税号
        taxType: "", // 纳税类型
        taxTypeName: "", //纳税类型名称-----
        remarks: "", //备注
        isEnableAccount: false,
        isEnableSell: false,
        codeNumber: "",
      },
      systemGather: {
        codePreSets: [],
        customerIndusts: [],
        cloneZtInfos: [],
      },
      isConfirmLoading: false,
      modificationL: false, // 新建/编辑状态
      examine: true, // 查看状态
      isButton: false, // 取消 保存
      accountName: false, // 新建状态
      paragraph: true, // 新建状态
      paragraphs: false,
      clonestate: false, // 克隆
      establish: true, // 创建
      tochannel: true, // 导入
      itemName: "", // 导航
      loading: false,
      dialogVisible: false, // 一键导入弹框
      iframeSrc: "",
      isCard: false, // 是否导入
      isSucceed: false, // 是否导入成功
      ExcelVisible: false, // Excel导入弹框
      Excelblenel: false, // Excel导入弹框
      isMoreBooksSet: true, // 一键式
      isMoreBooksEXcel: true, // Excel导入
      rules: {
        subName: [
          { required: true, message: "请输入企业名称", trigger: "change" },
          { min: 1, max: 25, message: "长度在 1 到 25 个字符", trigger: "change" },
        ],
        abbreviationName: [{ required: true, message: "请输入企业简称", trigger: "change" }],
        taxNumber: [
          { required: true, message: "请输入税号", trigger: "change" },
          { min: 18, max: 18, message: "长度为 18 个字符", trigger: "change" },
        ],
        subNumber: [{ required: true, message: "请输入企业编码", trigger: "change" }],
        accountCode: [{ required: true, message: "请输入账套编码", trigger: "change" }],
        taxType: [{ required: true, message: "请选择报税类别", trigger: "change" }],
        ShareStaffID: [{ required: true, message: "请选择负责会计", trigger: "change" }],
        startYm: [{ required: true, message: "请选择月份", trigger: "change" }],
        accountingSystemName: [{ required: true, message: "请选择会计制度", trigger: "change" }],
        cloneAccountId: [{ required: true, message: "请选择克隆账套", trigger: "change" }],
        IndustryName: [{ required: true, message: "请选择所属行业", trigger: "change" }],
        remarks: [
          { required: false, message: "", trigger: "blur" },
          { max: 200, message: "最多200个字符", trigger: "blur" },
        ],
        // businessScope: [
        //     { required: false, message: '', trigger: 'blur' },
        //     { max: 1000, message: '最多1000个字符', trigger: 'blur' }
        // ],
        codeNumber: [{ validator: Vrules.isIdCard, trigger: "change" }],
      },

      // 新增克隆账套 -----------------------
      Enable: false,
      Visiblenel: false, // 一键导入弹框
      Information1: {
        accountType: 0,
        accountingSystemId: "",
        cloneAccountId: "",
        startYm: "",
        industryid: "",
      },
      codePreSets: [],
      customerIndusts: [],
      cloneZtInfos: [],
      rules1: {
        startYm: [{ required: true, message: "请选择月份", trigger: "change" }],
        accountingSystemId: [{ required: true, message: "请选择会计制度", trigger: "change" }],
        cloneAccountId: [{ required: true, message: "请选择克隆账套", trigger: "change" }],
        industryid: [{ required: true, message: "请选择所属行业", trigger: "change" }],
      },
    };
  },
  computed: {
    ...mapState({
      userInfo: (state) => state.common.userInfo,
      Edit: (state) => state.companyInfo.Edit,
      newInformation: (state) => state.companyInfo.newInformation,
      subid: (state) => state.companyInfo.subid,
      examineVux: (state) => state.companyInfo.examineVux,

      tagCurrent: (state) => state.tag.tagCurrent,
      tagList: (state) => state.tag.tagList,
    }),
  },
  methods: {
    goNotice() {
      this.$router.push({ name: "notice" });
    },

    edit() {
      // 编辑
      this.isButton = !this.isButton;
      this.modificationL = true;
      this.examine = false;
      this.accountName = true;
      this.paragraph = false;
      // rormBood
      if (this.Information.bankShareholderList) {
        this.Information.bankShareholderList.forEach((item) => {
          item.rormBood = true;
        });
      }
    },

    activeItemNav(item) {
      // 工商信息 |  税务、银行、股东信息 切换
      this.navs.forEach((nav) => {
        nav.isActive = item.name === nav.name;
      });
      this.itemName = item.name;
      if (this.itemName === "工商信息") {
        this.isBusiness = true;
      } else if (this.itemName === "税务、银行、股东信息") {
        this.isBusiness = false;
      }
    },

    Getcoverinformation() {
      // 获取公司信息
      this.$api.companyInfo.Detail({ subid: this.subid }).then((res) => {
        let result = res.data.data;
        if (res.status === 200) {
          this.Information = { ...this.Information, ...result };
          this.Information.guid = this.Information.importid;
          if (result.businessModel) {
            this.businessModel = result.businessModel[0];
            this.Information.codeNumber = this.businessModel.codeNumber;
            // this.Information.businessScope=this.businessModel.businessScope
          }
          if (result.taxationModel) {
            this.taxationModel = result.taxationModel[0];
            this.Information.dsPwd = this.taxationModel.dsPwd;
            this.Information.gsPwd = this.taxationModel.gsPwd;
          }
          if (this.Information.bankShareholderList && this.Information.bankShareholderList.length != 0) {
            this.Information.bankShareholderList.map((item) => {
              this.$set(item, "rormBood", false);
              return item;
            });
            this.Banks = this.Information.bankShareholderList.filter((item) => {
              return item.type == 1;
            });
            this.Shareholds = this.Information.bankShareholderList.filter((item) => {
              return item.type == 2;
            });
          }
          if (this.Edit || this.isEdit) {
            this.Modified();
          }
          if (!this.Information.taxType) {
            this.Information.taxType = "";
          }
          if (!this.Information.codeNumber) {
            this.Information.codeNumber = "";
          }
        }
        this.loading = false;
      });
    },

    addAttachment() {
      // 添加账套
      let Shareholds = this.Shareholds;
      let Banks = this.Banks;

      let successShareholds = [];
      var regIdNo = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
      for (let i = 0; i < Shareholds.length; i++) {
        if (Shareholds[i].bankShareName && !Shareholds[i].code) {
          // if (!Shareholds[i].code) {
          this.$message({ message: `请输入第${i + 1}行的身份证号`, type: "warning" });
          return false;
          // }
        } else if (Shareholds[i].code) {
          if (!regIdNo.test(Shareholds[i].code)) {
            this.$message({ message: `第${i + 1}行身份证格式错误请重新输入！`, type: "warning" });
            return false;
          }
        }

        //名称或账号一个不为空即进入添加
        if (Shareholds[i].bankShareName || Shareholds[i].code) {
          successShareholds.push(Shareholds[i]);
        }
      }
      let successBanks = [];

      let regIdNo_Bank = /^([1-9]{1})(\d{14}|\d{18})$/;
      for (let i = 0; i < Banks.length; i++) {
        if (Banks[i].bankShareName && !Banks[i].code) {
          // if (!Banks[i].code) {
          this.$message({ message: `请输入第${i + 1}行的银行卡号`, type: "warning" });
          return false;
          // }
        } else if (Banks[i].code) {
          if (!regIdNo_Bank.test(Banks[i].code)) {
            this.$message({ message: `第${i + 1}行银行卡号格式错误请重新输入！`, type: "warning" });
            return false;
          }
        }
        //名称或账号一个不为空即进入添加
        if (Banks[i].bankShareName || Banks[i].code) {
          successBanks.push(Banks[i]);
        }
      }

      let bankShareholderList = [...successShareholds, ...successBanks];
      let params = {
        ...this.Information,
        businessModel: [],
        taxationModel: [],
        bankShareholderList,
        taxType: Number(this.Information.taxType),
      };
      // params.parentId = this.parentId
      if (this.taxationModel.dsPwd || this.taxationModel.gsPwd) {
        params.taxationModel = [this.taxationModel];
      }

      for (let key in this.businessModel) {
        if (this.businessModel[key]) {
          params.businessModel = [this.businessModel];
        }
      }
      if (params.accountType == 1) {
        params.accountingSystemId = 0;
      } else if (params.accountType == 2) {
        params.accountingSystemId = 0;
        params.industryid = 0;
        params.importid = params.guid;
      }

      this.$delete(params, "dsPwd");
      this.$delete(params, "gsPwd");
      this.$delete(params, "codeNumber");
      this.$delete(params, "businessScope");
      this.$delete(params, "guid");
      this.$delete(params, "visibleUserList");
      if (!this.examineVux) {
        // 新增
        if (this.Information.isEnableAccount) {
          this.$refs.Information1.validate((valid) => {
            if (valid) this.addAccountSet(params);
            else this.addAccountSet(params);
          });
        } else {
          this.AddSubCompanyAccount(params);
        }
      } else {
        params.bankShareholderList.forEach((item) => {
          item.rormBood = false;
        });
        this.isConfirmLoading = true;
        this.$api.companyInfo
          .EditSubCompany(params)
          .then(() => {
            this.isButton = !this.isButton;
            this.modificationL = false;
            this.examine = true;
            this.isConfirmLoading = false;
            this.loading = false;
            this.closeCurrentTags(1);
            this.$notify({ title: "成功", message: "修改成功", type: "success", duration: 1000 });
            GetSubCompanyDataView(this);
          })
          .catch(() => {
            this.isConfirmLoading = false;
            this.loading = false;
          });
      }
    },

    cancel(Information) {
      // 取消
      this.examine = true;
      this.modificationL = false;
      this.isButton = false;
      this.paragraph = true;
      this.accountName = false;
      if (this.newInformation) {
        this.$router.back();
        this.isMoreBooksSet = true;
        this.isMoreBooksEXcel = true;
        return;
      }
      this.$store.commit("EditAccount", false); // 编辑状态为 false
      this.$refs[Information].resetFields();
      this.Getcoverinformation(); // 重新获取账套信息
    },

    preserve(Information) {
      // 保存
      this.$refs[Information].validate((valid) => {
        if (valid) {
          this.addAttachment();
        }
      });
    },

    AddSubCompanyAccount(obj, obj1) {
      // 新增
      let params = {
        ...obj,
        ...obj1,
      };
      this.isConfirmLoading = true;
      this.$api.companyInfo
        .AddSubCompanyAccount(params)
        .then((res) => {
          if (res.data.status == 200) {
            if (params.accountType == 2) {
              this.$store.commit("DEL_TAG", this.tagCurrent);
              this.$router.push({ name: "cancelAccountContainer", query: { isGetData: true, accountType: params.accountType, abbreviationName: params.subName, subid: res.data.data } });
            } else {
              this.closeCurrentTags(1); // accountType 为2时跳转导入账套
            }
            this.$notify({ title: "成功", message: "新增成功", type: "success", duration: 1000 });
            GetSubCompanyDataView(this);
          } else {
            // this.$message({message:res.data.message, type:'warning'})
          }
          this.isConfirmLoading = false;
        })
        .catch(() => {
          this.isConfirmLoading = false;
        });
    },
    openAccount() {
      // 新建 或 查看 或 编辑
      if (this.newInformation) {
        this.accountName = true;
        this.examine = false;
        this.paragraph = false;
        this.paragraphs = true;
        this.modificationL = true;
        this.isButton = true;
        this.Information.guid = this.guid();
        this.Marxist();
        this.Modified();
        this.GetSubNumber(); // 新增获取编码
      }
      if (this.examineVux) {
        this.accountName = false;
        this.examine = true;
        this.modificationL = false;
        this.Getcoverinformation();
      }
      if (this.Edit) {
        this.$store.commit("EditAccount", true);
        this.isButton = true;
        this.examine = false;
        this.paragraph = false;
        this.accountName = true;
        this.modificationL = true;
        this.Getcoverinformation();
      }
    },

    deleteTable(index) {
      // del银行信息
      if (this.Banks.length === 1) {
        this.$message({
          message: "不可删除",
          type: "warning",
        });
      } else {
        this.Banks.splice(index, 1);
      }
    },

    addIncreased() {
      // 新增银行
      let obj = {
        bankShareName: "", // 开户行
        code: "", // 账号
        type: 1, //代表银行
        rormBood: true,
      };
      this.Banks.push(obj);
    },

    deleteTablex(index) {
      // 删除股东
      if (this.Shareholds.length === 1) {
        this.$message({
          message: "不可删除",
          type: "warning",
        });
      } else {
        this.Shareholds.splice(index, 1);
      }
    },

    addIncreasedx() {
      // 添加股东信息
      let obj = {
        bankShareName: "", // 股东姓名
        code: "", // 身份证号码
        type: 2, //代表股东
        rormBood: true,
      };
      this.Shareholds.push(obj);
    },

    changetaxTypeName(val) {
      // set taxTypeName
      if (val == 2) {
        this.Information.taxTypeName = "一般纳税人";
      } else if (val == 1) {
        this.Information.taxTypeName = "小规模纳税人";
      }
    },

    Modified() {
      // 是否新增 股东信息 |银行信息
      if (this.Banks.length === 0) {
        this.addIncreased();
      } else {
        this.Banks.map((item) => {
          item.rormBood = true;
        });
      }
      if (this.Shareholds.length === 0) {
        this.addIncreasedx();
      } else {
        this.Shareholds.map((item) => {
          item.rormBood = true;
        });
      }
    },

    guid() {
      //生成随机 GUID 数
      function S4() {
        return ((1 + Math.random()) * 0x10000 | 0).toString(16).substring(1);
      }
      return S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4();
    },
    // 新增 克隆 账套
    close() {
      this.Visiblenel = false;
      // this.RegExistAccount()
    },
    Marxist() {
      // 获取账套添加需要的信息
      this.$api.accountPort.GetSelectSystemList().then((res) => {
        let resData = [];
        res.data.data.map((item) => {
          if (this.userInfo.smallType == 3) {
            if (item.systemName != "小企业会计准则(2013智能做账)") {
              resData.push(item);
            }
          } else {
            resData.push(item);
          }
        });
        this.codePreSets = resData;
      });
      this.$api.accountPort.GetSelectIndustryList().then((res) => {
        this.customerIndusts = res.data.data;
      });
      this.$api.companyInfo.GetSelectCompanyNameList().then((res) => {
        this.cloneZtInfos = res.data.data;
      });
    },

    GetSubNumber() {
      // 新增获取编码
      this.$api.companyInfo.GetSubNumber().then((res) => {
        this.Information.subNumber = res.data.data;
      });
    },

    Oneclickimport() {
      // 一键式导入
      this.$confirm("若导入多年度的账套，请先导最新年限的，导入顺序案例：2019→2018→2017→2016。", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          let params = {
            subid: this.userInfo.subid,
          };
          this.$api.companyInfo.Detail(params).then((res) => {
            let Information = res.data.data;
            //   Information.accountingSystemId=Number(Information.accountingSystemId)
            //   Information.industryid=Number(Information.industryid)
            // Information.importid = this.guid();
            // Information.taxType = Number(Information.taxType);
            // Information.accountType = 2;

            let copyinformation = JSON.stringify({
              subid: Information.subid,
              subName: Information.subName,
              abbreviationName: Information.abbreviationName,
              createName: Information.createName,
              importid: this.guid(),
              accountType: 2,
              companyid: this.userInfo.CompanyId,
              createid: this.userInfo.UserId,
              taxTypeName: Information.taxTypeName,
            });
            let name = escape(this.userInfo.abbreviationName || this.userInfo.subName);
            let copyinformations = escape(copyinformation);
            let radom = Math.random() * 100;
            let baseurl = webUrl.importData;
            // if (process.env.NODE_ENV == 'checkTest' || process.env.NODE_ENV == 'development' || process.env.NODE_ENV == 'pre') {
            //   baseurl = 'http://import.91yikuaiji.com/ImportZT/ZTImport.htm';
            // } else if (process.env.NODE_ENV == "prod" || process.env.NODE_ENV == "newProd") {
            //   baseurl = 'https://upgrade.yundaizhang.com.cn:8442/ImportZT/ZTImport.htm';
            // }
            this.iframeSrc = `${baseurl}?cname=${name}&userid=${this.userInfo.UserId}&dbkey=4&typeKey=4&radom=${radom}&accountjson=${copyinformations}`;
            this.Visiblenel = true;
          });
        })
        .catch(() => {});
    },

    addAccountSet(obj) {
      // 新增|克隆账套
      let params = {
        ...this.Information1,
        // subid:this.userInfo.subid
      };

      if (params.accountType == 0) {
        if (!params.startYm || !params.industryid || !params.accountingSystemId) {
          return;
        }
      } else if (params.accountType == 1) {
        if (!params.startYm || !params.industryid || !params.cloneAccountId) {
          return;
        }
      }
      if (params.accountType != 2) {
        let industry = this.customerIndusts.find((item) => {
          return item.id == params.industryid;
        });
        params.industryName = industry.industryName;
      } else {
        obj.isEnableAccount = false;
      }
      if (params.accountType == 0) {
        delete params.cloneAccountId;
        let accounting = this.codePreSets.find((item) => {
          return item.id == params.accountingSystemId;
        });
        params.accountingSystemName = accounting.systemName;
      } else {
        delete params.accountingSystemId;
      }
      if (params.accountType == 1) {
        params.accountingSystemId = 0;
      } else if (params.accountType == 2) {
        params.accountingSystemId = 0;
        params.industryid = 0;
      }
      this.AddSubCompanyAccount(obj, params);
      // this.isConfirmLoading = true
      // this.$api.companyInfo.AddAccount(params).then(res=>{
      //     this.isConfirmLoading = false
      //     if(res.data.status ==200){
      //         this.$message({  message: params.accountType ==0?'创建成功':'克隆成功',type: 'success'})
      //         this.RegExistAccount()
      //     }
      // }).catch(()=>{
      //     this.isConfirmLoading = false
      // })
    },

    GetInformation() {
      // 获取工商信息
      let params = {
        companyName: this.Information.subName,
      };
      if (!params.companyName) {
        this.$message({ message: "账套名称不可为空", type: "warning" });
        return;
      }
      this.loading = true;
      this.$api.accountPort.GetBusinessInfo(params).then((res) => {
        let result = res.data;
        this.loading = false;
        if (result.data == null) {
          this.$message({ message: "查询无结果", type: "warning" });
          return;
        }
        if (result.status === 200 && result !== "null") {
          this.substitute(result.data);
        }
      });
    },
    substitute(newcome) {
      // 工商信息赋值
      if (!newcome.dutyParagraph) {
        newcome.dutyParagraph = "";
      }
      if (!newcome.registrationType) {
        newcome.registrationType = "";
      }
      if (!newcome.registeredCapital) {
        newcome.registeredCapital = "";
      }
      if (!newcome.establishDate) {
        newcome.establishDate = "";
      } else {
        // let time = newcome.establishDate.split(' ')[0].split('/');
        // let time1 = time[2] + '-' + time[0] + '-' + time[1];
        // let estabDate = new Date(time1);
        // let moth = estabDate.getMonth() + 1;
        // let data = estabDate.getDate();
        // moth = moth < 10 ? '0' + moth : moth;
        // data = data < 10 ? '0' + data : data;
        // newcome.establishDate = estabDate.getFullYear() + '-' + moth + '-' + data;
      }

      if (!newcome.address) {
        newcome.address = "";
      }
      if (!newcome.businessScope) {
        newcome.businessScope = "";
      }
      if (!newcome.legal) {
        newcome.legal = "";
      }
      if (!newcome.shareholds) {
        newcome.shareholds = "";
      }
      this.Information.taxNumber = newcome.dutyParagraph;
      this.businessModel.typeName = newcome.registrationType;
      this.businessModel.registerCapital = newcome.registeredCapital;
      // this.businessModel.buildDateStr = newcome.establishDate;
      this.businessModel.buildDate = newcome.establishDate;
      this.businessModel.address = newcome.address;
      this.businessModel.businessScope = newcome.businessScope;
      // this.Information.businessScope = newcome.businessScope
      this.businessModel.legalPerson = newcome.legal;
      this.businessModel.Shareholds = newcome.shareholds;
    },

    // RegExistAccount(){
    //     let params = {
    //         subid:this.userInfo.subid
    //     }
    //     this.$api.companyInfo.RegExistAccount(params).then(res=>{
    //         if(!res.data.data){
    //             this.Marxist()
    //             this.isShow = 1
    //             this.loading = false
    //         }else{
    //             this.isData = res.data.data
    //             this.Entertheaccount()
    //         }
    //     })
    // },

    closeCurrentTags(type) {
      // 关闭当前tags
      this.$store.commit("DEL_TAG", this.tagCurrent);
      if (type == 1) {
        if (this.$route.query.type == 1) return this.$router.back();
        this.$router.push({ name: "cancelAccountContainer", query: { isGetData: true } });
      } else {
        this.$router.back();
      }
    },

    eachTag(tag) {
      for (var key in this.tagList) {
        if (this.tagList[key].value === tag.value) {
          return key;
        }
      }
      return -1;
    },
  },
  mounted() {},
  activated() {},
};
</script>
<style lang="less">
#editCompany {
  width: 100%;
  height: 100%;
  padding: 0;
  overflow: hidden;
  .demo-ruleForm {
    width: 100%;
    // height: calc(100% - 60px)
    height: 100%;
    float: left;
  }
  .information_left {
    width: calc(100% - 380px);
    height: calc(100% - 60px);
    overflow: hidden;
    overflow-y: auto;
    box-sizing: border-box;
    float: left;
    .el-col-24 {
      width: 93%;
      height: 40px;
      margin-left: 3%;
      box-shadow: 0px 0px 8px #d4dcf0;
      border: none;
      margin-top: 30px;
      background-color: #f7f8fc;
      .span_blo {
        width: 100%;
        height: 100%;
        line-height: 40px;
        padding-left: 3%;
        ._span {
          display: inline-block;
          line-height: 40px;
          font-size: 15px;
        }
        .__span {
          margin-left: 20px;
          color: #f49c2a;
          font-size: 16px;
        }
      }
    }
    .information_left_List {
      float: left;
      width: 100%;
      position: relative;
      .item {
        float: left;
        margin-left: 6%;
        margin-top: 20px;
        span {
          display: inline-block;
          color: #333;
          font-size: 14px;
        }
        p {
          display: inline-block;
          font-size: 15px;
          margin-left: 5px;
          color: rgb(143, 137, 137);
          font-weight: 500;
        }
        .itemspan {
          margin-right: 31px;
        }
        .item_text {
          display: inline-block;
          font-size: 15px;
          color: rgb(143, 137, 137);
          font-weight: 500;
        }
      }
      .redact {
        float: left;
        margin-top: 20px;
        width: 30%;
        text-align: justify;
        span {
          display: inline-block;
          color: #333;
          font-size: 14px;
        }
        p {
          display: inline-block;
          margin-left: 5px;
          font-size: 15px;
          color: rgb(143, 137, 137);
          font-weight: 500;
        }
        .itemspan {
          margin-right: 31px;
        }
        .el-textarea {
          width: 80%;
        }
      }
      .duty {
        float: left;
        margin-top: 20px;
        text-align: justify;
        margin-left: 5.5%;
        span {
          display: inline-block;
          color: #333;
          font-size: 16px;
        }
        p {
          display: inline-block;
          margin-left: 5px;
          font-size: 15px;
          color: rgb(143, 137, 137);
          font-weight: 500;
        }
        .itemspan {
          margin-right: 31px;
        }
        .el-textarea {
          width: 80%;
        }
      }
      .noleft {
        margin-left: 5.5%;
      }
      .first {
        margin-left: 5.5%;
      }
      .anchor {
        margin-left: 20%;
      }
      .itemlength {
        width: 100%;
        .el-input {
          width: 72.2%;
        }
      }
      .el-input {
        width: 60%;
        margin-left: 6px;
      }
      .el-cascader {
        .el-input {
          width: 100%;
        }
        .el-cascader__tags {
          left: 5px;
        }
      }
      .el-cascader--small {
        width: 160px;
      }
      .Remarkstyle {
        float: left;
        width: 90%;
        margin-left: 7px;
        .el-form-item__content {
          margin-left: 0 !important;
        }
      }
      .ScopeStyle {
        float: left;
        width: 90%;
        margin-left: 7px;
        .el-form-item__content {
          margin-left: 0 !important;
        }
      }
      .IDNumberStyle {
        width: 70%;
        float: left;
        margin-top: -1%;
        margin-bottom: 10%;
        .el-form-item__content {
          margin-left: 0 !important;
          .el-input {
            width: 100% !important;
          }
        }
      }
      .IDNumberSpan {
        display: inline-block;
        float: left;
      }
      .TaxPasswordStyle {
        width: 200px;
        float: left;
        margin-top: -2%;
        .el-form-item__content {
          margin-left: 0 !important;
          .el-input {
            width: 100% !important;
          }
        }
      }
    }
    .IndustryDocument {
      display: inline-block;
      width: 100%;
      // height: 100%;
      padding: 0 45px;
      .IndustryDocument_title {
        float: left;
        margin: 2% 0;
        font-size: 14px;
        .title_span {
          width: 3px;
          height: 14px;
          display: inline-block;
          background-color: #5d8fff;
          margin-right: 5px;
          margin-top: 3px;
          float: left;
        }
      }
    }
    .theForm {
      width: 92%;
      margin-top: 20px;
      float: left;
      margin-left: 4%;
      .el-form-item--small.el-form-item {
        float: left;
        margin-left: 5px;
      }
      .business_span {
        float: left;
        font-size: 12px;
        line-height: 34px;
        color: #39a4ed;
        cursor: pointer;
        transform: scale(0.9);
      }
      .el-form-item__label {
        color: #333;
        font-size: 14px;
        padding: 0 6px 0 0;
      }
      .spaci {
        width: 38%;
        // .el-form-item__content{margin-left:0!important;float: left;width: 60%}
      }
      .spaci1 {
        width: 25%;
      }
    }

    .territory {
      width: 92%;
      margin-top: 20px;
      float: left;
      margin-left: 4%;
      .el-form-item--small.el-form-item {
        float: left;
        margin-left: 5px;
      }
      // .el-form-item__content{float: left;width: 85.5%;}
      // .el-form-item--small.el-form-item{display: flex; width:63%;margin: 0;}
      .el-form-item__label {
        color: #333;
        font-size: 14px;
        padding: 0 6px 0 0;
      }
      .taxNumber {
        width: 38%;
        // margin-left: 0.3% !important;
        // .el-form-item__content{margin-left:0!important;float: left;width: 60%;}
      }
      .taxType1 {
        width: 26%;
      }
    }
    .el-table__header th {
      background-color: #fff;
      font-size: 14px;
    }
    .el-table--enable-row-hover .el-table__body tr:hover > td {
      background-color: #fff;
    }
    .el-table th > .cell {
      vertical-align: baseline;
    }
  }

  .information_right {
    width: 380px;
    height: calc(100% - 60px);
    float: right;
    .el-col-24 {
      width: 93.5%;
      height: 40px;
      box-shadow: 0px 0px 8px #d4dcf0;
      border: none;
      margin-top: 30px;
      background-color: #f7f8fc;
      .span_blo {
        ._span {
          display: inline-block;
          margin-left: 8%;
          line-height: 40px;
          font-size: 15px;
        }
        .__span {
          margin-left: 20px;
          color: #f49c2a;
          font-size: 16px;
          text-decoration: underline;
          cursor: pointer;
        }
      }
    }
    .information_right_bottom_List {
      float: left;
      width: 92%;
      li {
        float: left;
        margin-top: 8%;
        margin-left: 8%;
        ._span {
          display: inline-block;
          color: #333;
          font-size: 15px;
        }
        p {
          display: inline-block;
          margin-left: 5px;
          font-size: 15px;
          color: rgb(143, 137, 137);
          font-weight: 500;
        }
      }
    }
    .el-radio-group {
      margin-top: 24px;
      margin-left: 6%;
      .el-radio {
        margin-right: 15px;
      }
    }
    .el-input--small {
      margin-left: 5px;
      width: 194px;
    }
    .ImportStyle {
      width: 94%;
      height: 50%;
      padding-left: 30px;
      padding-top: 15px;

      .ImportStyle_top {
        float: left;
      }
      .ImportStyle_bottom {
        float: left;
        margin-top: 15px;
      }
      .netspan {
        font-size: 12px;
        display: inline-block;
        color: red;
        padding-bottom: 10px;
      }
      .Importspan {
        width: 23%;
        display: inline-block;
        font-size: 12px;
        color: #333;
        padding-bottom: 10px;
      }
    }
    .sidethecheck {
      float: left;
      margin-top: 8%;
      margin-left: 4%;
      .el-form-item__label {
        color: #333;
        font-size: 14px;
        padding: 0 6px 0 0;
      }
      .el-form-item--small.el-form-item {
        float: left;
        margin-bottom: 5.5%;
      }
    }
    .el-form-item {
      float: left;
      width: 90%;
    }
    .el-form-item__label {
      color: #333;
    }
  }
  .informationWidth {
    width: 100%;
  }
  .information_bottom {
    width: 100%;
    height: 60px;
    line-height: 60px;
    text-align: center;
    border-top: 1px solid #edecf6;
    background-color: #fff;
    z-index: 10;
    float: left;
  }
  ._span {
    .el-switch {
      margin-left: 10px;
      position: relative;
      top: -2px;
    }
  }
  .Visiblenel {
    .el-dialog__body {
      height: 450px;
    }
  }
  .item {
    float: left;
    margin-left: 6%;
    padding-top: 5px;
    span {
      display: inline-block;
      color: #333;
      font-size: 14px;
    }
    p {
      display: inline-block;
      font-size: 15px;
      margin-left: 5px;
      color: rgb(143, 137, 137);
      font-weight: 500;
    }
  }
}
</style>
